const { createProxy } = require('./build/proxy')
const { defineConfig } = require('@vue/cli-service')

/**
 * api_prefix: 前缀
 * target: 代理地址
 * change_origin: 是否允许跨域
 * ws: 是否支持websocket请求
 * rewrite_path: 是否将前缀重写   是字符串就重写，否则不重写
 */
const server_proxy = [
  {
    api_prefix: "/api",
    target: "http://127.0.0.1:4523/m1/2928358-0-default",
    change_origin: true,
    ws: true,
    rewrite_path: '',
  },
]

module.exports = defineConfig({
  transpileDependencies: true,
  css: {
    sourceMap: true, // 开启 CSS source maps?
    loaderOptions: {
      less: {
        lessOptions: {
          modifyVars: {
            // 引入你的主题颜色
            hack: `true; @import "@/theme/antdv/index.less";`,
          },
          javascriptEnabled: true,
        },
      },
    },
  },
  devServer: {
    port: 8080,
    open: false,     // 是否自动打开浏览器
    hot: true, // 开启HMR
    proxy: {
      ...createProxy(server_proxy),
    }
  },
})
